require(["config"],function(){
    require(["jquery","lightTip","cookie","header"],($,LightTip)=>{
        
        function Register(){
            this.init();
        }
        Register.prototype={
            constructor:Register,
            init(){
               
                // $('#submit').click(function() {
                //     var elSearch = $('input');
                //     if (elSearch.val() == '') {
                //         elSearch.errorTip('尚未输入搜索内容');
                //     }
                // });
               $("#form").submit($.proxy(this.registerHandler,this))
            
            },
            registerHandler(e){
               // $.lightTip.success("chengg")
                // new LightTip().success('修改成功');
       
                    var data = $("#form").serialize();
                   
                $.ajax({
                    url:"http://localhost:80/php/check.php",
                    type: "POST",
                    data:data,
                    dataType: "json",
                  
                })
                .done((data)=>{
                    if(data.res_code === 1){
                        var username = $("#username").val();
                        $.lightTip.success('注册成功');
                    $.cookie.json=true;
                    $.cookie("login-user",username,{path:"/",expires:7});
                        //  window.location.href="/";
                        
                    $("#form")[0].reset();
                    }else if(data.res_code === -1){
                        $.lightTip.error('注册失败,已存在');
                    }
                })
              
                return false;
            },
                
            
               
            },
       
        new Register();
    })
})